package com.myplans.server.util.converter;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.beanutils.Converter;
import org.apache.log4j.Logger;


public class DateCalendarConverter implements Converter {

	private static Logger logger = Logger.getLogger(DateCalendarConverter.class);

	@SuppressWarnings("rawtypes")
	@Override
	public Object convert(Class type, Object value) {
		if (value instanceof Calendar)
			return ((Calendar) value).getTime();
		else if (value instanceof Date) {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime((Date) value);
			return calendar;
		}

		logger.debug("Returning a null value, possibly a conversion error.");
		return null;
	}
}
